package miku.firstgame.net.pack
{
	import miku.firstgame.constrants.ProtocalConstants;
	import miku.firstgame.model.User;
	import miku.firstgame.net.ByteArrayEx;

	public class EnterRoomResponsePack extends AbstractReponsePack
	{
		public var result:int;
		public var roomId:int;
		public var masterId:int;
		public var users:Vector.<User>;

		public function EnterRoomResponsePack(data:ByteArrayEx)
		{
			super(data);
			users = new Vector.<User>();
		}

		override public function decode():void
		{
			//前两位是tag,后两位是状态 0x0001是加密 ,0x0002是其他值
			super.decode();

			data.position = 4;
			result = data.readUnsignedByte();
			if (result == 0)
			{
				roomId = data.readUnsignedInt();
				masterId = data.readUnsignedInt();
				//TODO USERS
				var readyIds:Vector.<int> = new Vector.<int>();
				var readyCount:int = data.readShort();
				for (var j:int = 0; j < readyCount; j++)
				{
					readyIds.push(data.readUnsignedInt());
				}

				var userCount:int = data.readUnsignedInt();
				for (var i:int = 0; i < userCount; i++)
				{
					var user:User = User.parseUser(data);
					if (-1 != readyIds.indexOf(user.id))
					{
						user.isReady = true;
					}
					else
					{
						user.isReady = false;
					}
					users.push(user);
				}

			}
			else if (result == 2) //房间人数已满
			{

			}
			else if (result == 3) //房间已经开始游戏
			{

			}
		}

		override public function get tag():int
		{
			return ProtocalConstants.ENTER_ROOM;
		}

	}
}
